package com.winchain.chainbill.bill.biz.receive.service.impl;

import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.persistence.annotation.Pagination;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.framework.utils.CommonDataUtil;
import com.winchain.chainbill.bill.base.dao.CbRecDao;
import com.winchain.chainbill.bill.base.service.CbAttService;
import com.winchain.chainbill.bill.biz.query.vo.CbRecQueryVo;
import com.winchain.chainbill.bill.biz.query.vo.CbRecVo;
import com.winchain.chainbill.bill.biz.receive.service.BillRcvQueryService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("billRcvQueryService")
public class BillRcvQueryServiceImpl implements BillRcvQueryService {
	@Autowired
	private CbRecDao cbRecDao;
	@Autowired
	private CbAttService cbAttService;

	@Pagination
	public List<CbRecVo> selectBillForRcvByPage(PageLimit limit, CbRecQueryVo recordQueryVo) {
		if (StringUtil.notEmpty(recordQueryVo.getBillCode())) {
			recordQueryVo.setBillCode(StringUtil.getParameterLike(recordQueryVo.getBillCode()));
		}
		String[] billStates = { "S003" };
		recordQueryVo.setSellerId(CommonDataUtil.getCurEntId());
		recordQueryVo.setBillStates(billStates);
		return this.cbRecDao.selectBillForRcv(recordQueryVo);
	}

	@Pagination
	public List<CbRecVo> selectBillForRcvApproveByPage(PageLimit limit, CbRecQueryVo recordQueryVo) {
		if (StringUtil.notEmpty(recordQueryVo.getBillCode())) {
			recordQueryVo.setBillCode(StringUtil.getParameterLike(recordQueryVo.getBillCode()));
		}
		String[] billStates = { "S025", "S027" };
		recordQueryVo.setBillStates(billStates);
		recordQueryVo.setFinId(CommonDataUtil.getCurEntId());
		return this.cbRecDao.selectBillForRcv(recordQueryVo);
	}

	public CbRecVo selectBillForRcv(String billId) {
		CbRecQueryVo recordQueryVo = new CbRecQueryVo();
		recordQueryVo.setBillId(billId);
		List<CbRecVo> cbRecordVos = this.cbRecDao.selectBillForRcv(recordQueryVo);
		if ((cbRecordVos != null) && (cbRecordVos.size() == 0)) {
			return null;
		}
		CbRecVo cbRecVo = (CbRecVo) cbRecordVos.get(0);
		this.cbAttService.setAtt(cbRecVo);
		return cbRecVo;
	}
}
